package com.loe.mvp.util

import android.app.Activity
import android.view.ViewGroup
import com.loe.mvp.BaseDialog
import com.loe.mvp.R
import com.loe.mvp.ext_view.setDelayClickListener
import kotlinx.android.synthetic.main.permission_tip_dialog.view.*

/**
 * 权限提示弹框
 *
 * @author 章路顺
 * @since 2023/10/13-11:00
 */
class PermissionTipDialog(activity: Activity) : BaseDialog(activity, R.layout.permission_tip_dialog)
{
    private var okCallback: (()->Unit)? = null
    private var cancelCallback: (()->Unit)? = null
    private var tip: String = ""

    fun okCallback(callback: ()->Unit): PermissionTipDialog
    {
        okCallback = callback
        return this
    }

    fun cancelCallback(callback: ()->Unit): PermissionTipDialog
    {
        cancelCallback = callback
        return this
    }

    fun tip(text: String): PermissionTipDialog
    {
        tip = text
        return this
    }

    override fun ViewGroup.onView()
    {
        setAnimation()

        textTip.text = tip

        buttonAgree.setDelayClickListener()
        {
            okCallback?.invoke()
            dismiss()
        }
        buttonCancel.setDelayClickListener()
        {
            cancelCallback?.invoke()
            dismiss()
        }
        dialog.setOnCancelListener()
        {
            cancelCallback?.invoke()
            dismiss()
        }
    }
}